
public class GongGongQianZhui {
    public static String longestCommonPrefix(String[] strs) {
            if(strs.length==1||strs.length==0){
                return strs[0];
            }
            String d="";
            int count=strs[0].length();

            for(int i=0;i<strs.length;i++){
                if(count>strs[i].length()){
                    count=strs[i].length();
                }
            }

            for(int j=1;j<=count;j++){
                for(int i=0;i<strs.length;i++){
                    if(!strs[i].substring(0,j).equals(strs[0].substring(0,j))){
                        break;
                    }
                    else if(strs[i].substring(0,j).equals(strs[0].substring(0,j))&&i==strs.length-1){
                        d=strs[0].substring(0,j);
                    }
                }
            }
            return d;
        }

    public static void main(String[] args) {
        String[] strs1 = {"flower","flow","flight"};
        String z=longestCommonPrefix(strs1);
        String s="qwertyuiop";
        for(int i=2;i<s.length();i++){
            String s1=s.substring(i-2,i);
            System.out.println(s1);
        }
        String s1=strs1[1].substring(0,1);
        if(s.equals(s1)){
            System.out.println(s);
        }
        System.out.println(z);
    }
}
